package com.jiangore.mapper;

import com.jiangore.entity.Member;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @Todo
 * @Author jiangtao
 * @CreateBy 2020-03-09 1:48 PM
 * @UpdateBy jiangtao
 * @Version v1.0
 */
public class MemberRowMapper implements RowMapper<Member> {

    @Override
    public Member mapRow(ResultSet rs, int i) throws SQLException {
        Date registerDate = rs.getDate("register_time");

        ZoneId zoneId = ZoneId.of("UTC+08:00");
        LocalDateTime dt = LocalDateTime.ofInstant(registerDate.toInstant(), zoneId);

        Member m = Member.builder()
                .id(rs.getInt("id"))
                .account(rs.getString("account"))
                .nickname(rs.getString("nickname"))
                .password(rs.getString("password"))
                .email(rs.getString("email"))
                .mobile(rs.getString("mobile"))
                .age(rs.getInt("age"))
                .registerTime(dt).build();

        return m;
    }
}
